﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class frmPalabrasReservadas : cGlobal
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.CargarPalabras();
        }
    }
    private void CargarPalabras()
    {
        DataSet ds;
        ds = objPlantilla.GetPalabraReservada();
        this.grdPalabras.DataSource = ds.Tables[0];
        this.grdPalabras.DataBind();
        this.grdPalabras.Columns[0].Visible = false;
    }
    protected void ImBtnNuevo_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            

            if (string.IsNullOrEmpty(this.TxtPlabra.Text.Trim()))
            {
                objJavaScript.jsAlert("Es necesario ingresar la palabra reservada.", Page);
                this.TxtPlabra.Focus();
                return;               
            }
             string Palabra;
            Palabra = this.TxtPlabra.Text.Trim();
            objPlantilla.CrearPalabraReservada(Palabra);
            this.TxtPlabra.Text = "";  
            CargarPalabras(); 
            objJavaScript.jsAlert("Se creo con exito la palabra reservada.", Page);


        }
        catch (Exception ex)
        {
        }
       

    }
    protected void grdPalabras_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Obtiene el id a eliminar
        int id = Convert.ToInt32(this.grdPalabras.DataKeys[e.RowIndex].Value.ToString());
        try
        {
            objPlantilla.EliminarPalabraReservada(id);
            this.TxtPlabra.Text = "";  
            objJavaScript.jsAlert("La Palabra reservada ha sido eliminada.", Page);
            this.CargarPalabras();
        }
        catch (Exception ex)
        {
            objJavaScript.jsAlert("Ocurrio un error al eliminar la palabra reservada", Page);
        }
    }
}
